package com.itheima.controller;

import com.itheima.domain.dto.EmpDto;
import com.itheima.domain.pojo.Emp;
import com.itheima.domain.vo.EmpVo;
import com.itheima.domain.vo.PageResult;
import com.itheima.domain.vo.Result;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/** Emp-员工管理
 * @author 上官徵羽
 * @version 1.0
 * @since 2025-08-15 20:34
 */
@RestController
@RequestMapping("/emps")
@Slf4j
public class EmpController {
    @Autowired
    private EmpService empService;

    /** 分页查询员工列表 */
    @GetMapping
    public Result getEmpPage(EmpDto empDto)
    {
        log.info("查询员工列表{}", empDto);
        PageResult<EmpVo> pageResult = empService.getEmpPage(empDto);
        return Result.success(pageResult);
    }

    /** 查询全部员工列表 */
    @GetMapping("/list")
    public Result getEmpList(){
        List<Emp> empList = empService.getEmpList();
        return Result.success(empList);
    }

    /** 新增员工 */
    @PostMapping
    public Result addEmp(@RequestBody Emp emp){
        empService.addEmp(emp);
        return Result.success();
    }

    /** 批量删除员工 */
    @DeleteMapping
    public Result removeEmp(@RequestParam Integer[] ids) throws Exception {
        empService.deleteEmp(ids);
        return Result.success();
    }

    /** 根据员工id查询员工信息 */
    @GetMapping("/{id}")
    public Result getEmpId(@PathVariable("id") Integer id){
        Emp emp = empService.getEmpId(id);
        return Result.success(emp);
    }

    /** 修改员工 */
    @PutMapping
    public Result updateEmp(@RequestBody Emp emp){
        empService.updateEmp(emp);
        return Result.success();
    }
}
